<?php

require 'class.DB.php';
//session_start();


//session_start();
$game=1;
$end_game=1 ;

$tarshipfrom=3;
$t_power=0.3;
  

    
       $end_game =mysql_query("SELECT  DISTINCT player  FROM planet WHERE map=0 &&  player!=-1 ", $db);
      
            
                  $ships_end=mysql_query("SELECT  user_id FROM ships  WHERE map=0", $db);
            
                 if($ships_end) echo'  est= ' .$ships_end;else echo' net ships_end' ;
                 
                   $planet_res=mysql_query("SELECT player  FROM planet WHERE map=0 &&  player!=-1 ", $db);
                   $planet_row=mysql_fetch_array($planet_res);
                   $planet_end=$planet_row['player'];
            
                $end_game=1; 
                               
               while ($myrow = mysql_fetch_array($ships_end))
                 {
                       if ( $myrow['player']!=$planet_end) $end_game=0; 
                  }
                  
           
  
 
    echo' planet_end '.$planet_end;
     echo'  $end_game  '.$end_game;
    echo' mysql_num_rows($ships_end)  '.mysql_num_rows($ships_end);
    
    $ran= rand(5, 15);
    $ran_ship= $ran*10 + rand(5, 30)*10; 
echo " ran ".$ran." ranship ".$ran_ship;

         $result = mysql_query("SELECT init FROM map WHERE id=0",$db);
         $myrow = mysql_fetch_array($result);
         $init_game=$myrow['init'];
echo " init ".$init_game;


   // $rv1=4;
   // $rv2=4;
$ra[1]=1000;
$ra[2]=3000;

$ff=3;
function rating($r1,$r2,$vin)
{
    global $ra;    global $mes; 
    
    if ($vin==1) { 
        $mes=$ra[2]/($ra[1]+$ra[2])*10 ;
        $ra[1]=$ra[1]+  $mes;  
        $ra[2]=$ra[2] - $mes;;   
        }
        
         if ($vin==2) { 
          $mes= $ra[1]/($ra[1]+$ra[2])*10;
        $ra[1]=$ra[1] -  $mes ;  
        $ra[2]=$ra[2] + $mes ;   
        }
        
        
        $r1=$r1+1;
} 

rating($ff,2,2);
echo' r1 '.($ra[1]).' r2 '.($ra[2]).' mes '.$mes.' ff '.$ff;


?>
